package com.github.cyf.config.datasource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * MyBatis 全局配置
 * @author chenyifan
 * @create 2024-03-13 12:25
 */
@Configuration
public class MyBatisGlobalConfiguration {

    /**
     * Configuration 里面关联了 DataSource，#Environment#DataSource
     * {@link org.apache.ibatis.session.Configuration#getEnvironment()}
     *
     * 所以每个数据源需要单独配置 Configuration
     * @return
     */
    @Bean
    @Scope("prototype")
    @ConfigurationProperties(prefix = "mybatis.configuration")
    public org.apache.ibatis.session.Configuration configuration() {
        return new org.apache.ibatis.session.Configuration();
    }

}
